/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.uefs.cedoc.controle.fundo;

import br.uefs.cedoc.controle.Command;
import br.uefs.cedoc.controle.CommandException;
import br.uefs.cedoc.controle.CommandToken;
import br.uefs.cedoc.db.exception.DBConnectionException;
import br.uefs.cedoc.db.fundo.DBFundo;
import br.uefs.cedoc.entidades.FundoBean;
import java.sql.SQLException;
import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author suporte
 */
public class AddFundoCommand implements Command {
    
    private String next;
    
    public AddFundoCommand(String next) {
        this.next = next;
    }
    
    public String execute(HttpServletRequest req)
    throws CommandException {
        try {
            if(CommandToken.isValid(req)){
            DBFundo dbfundo = new DBFundo();
            FundoBean fundo = new FundoBean();            
            fundo.setFonte(req.getParameter("fundo"));
            dbfundo.criarFundo(fundo);
            req.setAttribute("status.msg", "Fundo adicionado!");
            }
            else{
                req.setAttribute("status.msg", "Nao foi possivel adicionar!");
            }
            
            } catch (SQLException ex) {
                ex.printStackTrace();
            } catch (DBConnectionException ex) {
                ex.printStackTrace();
            }
        return next;

    }
}

